import type { Ref } from "vue";

/**
 * Select 选项接口
 */
export interface SelectOption {
  label: string;
  value: any;
  disabled?: boolean;
  icon?: string;
}

/**
 * Select Props
 */
export interface SelectProps {
  modelValue?: any;
  placeholder?: string;
  options?: SelectOption[];
  clearable?: boolean;
  filterable?: boolean;
  multiple?: boolean;
  selectWidth?: string;
  disabled?: boolean;
  size?: "sm" | "md" | "lg";
}

/**
 * Select 状态
 */
export interface SelectState {
  inputValue: string;
  options: Map<any, SelectOptionProxy>;
  cachedOptions: Map<any, SelectOptionProxy>;
  selected: SelectOptionProxy[];
  selectedLabel: string;
  hoveringIndex: number;
  inputHovering: boolean;
  expanded: boolean;
}

/**
 * Select Option Proxy (用于选项组件向 Select 注册自身)
 */
export interface SelectOptionProxy {
  value: any;
  label: string;
  currentLabel: string;
  disabled: boolean;
  visible: boolean;
  hover: boolean;
  itemSelected: boolean;
  isDisabled: boolean;
  selectOptionClick: () => void;
  updateOption?: (query: string) => void;
}

/**
 * Select Context（用于 provide/inject）
 */
export interface SelectContext {
  props: Ref<SelectProps> | SelectProps;
  state: SelectState;
  selectRef: HTMLElement | null;
  selectTriggerRef: HTMLElement | null;
  selectDropdownRef: HTMLElement | null;
  optionsArray: SelectOptionProxy[];
  setSelected: () => void;
  onOptionCreate: (vm: SelectOptionProxy) => void;
  onOptionDestroy: (key: any, vm: SelectOptionProxy) => void;
  handleOptionSelect: (option: SelectOptionProxy) => void;
}
